<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计出现最多的字符和次数</title>
    <script>
        var str = 'dbhfsghfgfbwhehfifgwiue';
        var one = {};
        for (var i = 0; i < str.length;i++) {
            var chars = str.charAt(i);
            if (one[chars]) {
                one[chars] ++;
            }
            else {
                one[chars] = 1;
            }
        }
        console.log(one);
        //
        var max = 0;
        var ch = '';
        for (var k in one) {
            //k 得到的属性名
            // one[k] 得到的是属性值
            if(one[k] > max) {
                max = one[k];
                ch = k;
            }
        }
        console.log(max);
        console.log('出现最多的字符是：' + ch);
        console.log('出现了' + max + '次');
    </script>
</head>

<body>

</body>

</html>